import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '首页',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'house'}
    }, {
      path: '/aListOfPendingTasks',
      name: '待处理任务列表',
      hidden: true,
      component: () => import('@/views/home/pendingList.vue'),
      meta: { title: '待处理任务列表'}
    }, {
      path: '/listOfNotificationAnnouncements',
      name: '通知公告列表',
      hidden: true,
      component: () => import('@/views/home/listOfNotificationAnnouncements.vue'),
      meta: { title: '通知公告列表'}
    }, {
      path: '/frequentlyUsedURLs',
      name: '常用网址',
      hidden: true,
      component: () => import('@/views/home/frequentlyUsedURLs.vue'),
      meta: { title: '常用网址'}
    }]
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/notificationAnnouncement/index',
    name: 'Example',
    children: [
      {
        path: '/table',
        name: 'Table',
        component: () => import('@/views/notificationAnnouncement/index'),
        meta: { title: '通知公告', icon: `notificationAnnouncement`},
      }
    ]
  },

  {
    path: '/documentManagement',
    component: Layout,
    redirect: 'documentManagement',
    meta: { title: '文档管理', icon: `documentManagement`},
    children: [
      {
        path: 'list',
        name: 'list',
        component: () => import('@/views/documentManagement/list/index'),
        meta: { title: '文档列表', icon: `listOfDocuments`},
      },
      {
        path: 'recycleBin',
        name: 'recycleBin',
        component: () => import('@/views/documentManagement/recycleBin/index'),
        meta: { title: '文档回收站', icon: `ticketRecycleBin`}
      }
    ]
  },
  {
    path: '/administrative',
    name: 'administrative',
    component: Layout,
    meta: {title: '行政管理', icon: `administration`},
    children: [
      {
        path: 'conferenceRoom',
        name: 'conferenceRoom',
        component: () => import('@/views/administrative/conferenceRoom/ConferenceRoomManagement/index.vue'),
        meta: {title: '会议室管理', icon: `leaveOfAbsenceApplication`},
        // children: [
          // {
          //   path: 'MeetingRoomReservation',
          //   name: 'MeetingRoomReservation',
          //   component: () => import('@/views/administrative/conferenceRoom/MeetingRoomReservation/index.vue'),
          //   meta: {title: '会议室预定', icon: `leaveOfAbsenceApplication`},
          // },
          // {
          //   path: 'MeetingRoomReservationManagement',
          //   name: 'MeetingRoomReservationManagement',
          //   component: () => import('@/views/administrative/conferenceRoom/MeetingRoomReservationManagement/index.vue'),
          //   meta: {title: '会议室预定管理', icon: `leaveOfAbsenceApplication`},
          // },
          // {
          //   path: 'ConferenceRoomManagement',
          //   name: 'ConferenceRoomManagement',
          //    meta: {title: '会议室管理', icon: `leaveOfAbsenceApplication`},
          // },
        // ]
      },
      // {
      //   path: 'cardPrinting',
      //   name: 'cardPrinting',
      //   component: () => import('@/views/administrative/cardPrinting/index.vue'),
      //   meta: {title: '用车管理', icon: `leaveOfAbsenceApplication`},
      // },
      {
        path: 'sealManagement',
        name: 'sealManagement',
        component: () => import('@/views/administrative/sealManagement/index.vue'),
        meta: {title: '用章管理', icon: `leaveOfAbsenceApplication`},
      },
      // {
      //   path: 'bookBorrowing',
      //   name: 'bookBorrowing',
      //   component: () => import('@/views/administrative/bookBorrowing/index.vue'),
      //   meta: {title: '图书借阅申请', icon: `leaveOfAbsenceApplication`},
      // },
      // {
      //   path: 'vehicleManagement',
      //   name: 'vehicleManagement',
      //   component: () => import('@/views/administrative/vehicleManagement/index.vue'),
      //   meta: {title: '名片印制流程', icon: `leaveOfAbsenceApplication`},
      // },
    ]
  },
  // {
  //   path: '/personnelManagement',
  //   component: Layout,
  //   redirect: '/personnelManagement/index',
  //   meta: { title: "人事管理", icon: `personnelManagement`},
  //   children:[
  //     {
  //       path: 'menu1-1',
  //       name: 'menu1-1',
  //       component: () => import('@/views/personnelManagement/menu1/menu1-1/LeaveApplicationForm.vue'),
  //       meta: {title: '请假申请', icon: `leaveOfAbsenceApplication`},
  //     },
  //     {
  //       path: 'menu1-2',
  //       name: 'menu1-2',
  //       component: () => import('@/views/personnelManagement/menu1/menu1-2/TravelApplicationForm.vue'),
  //       meta: {title: '出差申请', icon: `travelRequisition`},
  //     },
  //     {
  //       path: 'menu1-3',
  //       name: 'menu1-3',
  //       component: () => import('@/views/personnelManagement/menu1/menu1-3/IncomeCertificateForm.vue'),
  //       meta: {title: '收入证明流程', icon: `proofOfIncomeProcess`},
  //     },
  //   ]
  // },
  {
    path: '/systemAdministrator',
    component: Layout,
    redirect: 'systemAdministrator',
    meta: { title: '系统管理', icon: `systemAdministration`},
    children: [
      {
        path: 'organizationalStructure',
        name: 'organizationalStructure',
        component: () => import('@/views/systemAdministrator/organizationalStructure/index.vue'),
        meta: { title: '组织架构管理', icon: `organizationalStructureManagement`}
      },
      {
        path: 'theLogs',
        name: 'theLogs',
        component: () => import('@/views/systemAdministrator/theLogs/index.vue'),
        meta: { title: '操作日志', icon: `operationLogs`}
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/systemAdministrator/role/index.vue'),
        meta: { title: '角色管理', icon: `roleManagement`}
      },
      {
        path: 'uploadTheFile',
        name: 'uploadTheFile',
        component: () => import('@/views/systemAdministrator/uploadTheFile/index.vue'),
        meta: { title: '上传文件设置', icon: `uploadFileSettings`}
      },
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/systemAdministrator/user/index.vue'),
        meta: { title: '用户管理', icon: `userManagement`}
      },
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
